
<!DOCTYPE HTML>
<html lang="en">
<head>
    <link rel="stylesheet" href="__PUBLIC__/phone/css/styles.css" />
    <meta charset='UTF-8' />
    <meta name='generator' content='ecos.b2c' />
    <title>购物车</title>
    <meta name='keywords' content='' />
    <meta name='description' content='' />
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>


    <link href="__PUBLIC__/phone/css/zhuce_style.css" rel="stylesheet" media="screen, projection" />
    <script src="__PUBLIC__/phone/js/shop.min.js"></script>
    <style type="text/css">
        #J_total{
            position: fixed;
            bottom: 0;
            width: 100%;
            height: 50px;
            z-index: 9999;
        }
        .item3-cartnum{
            line-height: 20px;
            width: 20px;
            height: 20px;
            color: white;
            position: absolute;
            bottom: 35px;
            background: red;
            border-radius: 50%;
            left: 46%;
        }
    </style>
</head>
<body style="background-color: #F7F7F8;padding: 0;">
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?cdc1b98600fd737ffd391a2e9ad3bd57";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<div class="full-screen">
    <header style="background: #00a1f2;">
        <div class="a-bar">
            <a href="{:U('index')}" class="a-back">
                <i class="arr left" style="top: 0px;height: 10px;width: 10px;"></i>
            </a>
            <div class="a-name" style="color:white;">
                购物车
            </div>
        </div>
    </header>
    <div class="total" id="J_total">
        <div class="fixed-bar" style="height: 50px;">
            <div class="total-inner" style="padding: 0;">
                <div style="width: 65%;float: left;font-weight: normal;font-size: small;">
                    <div style=";margin-left: 6px;line-height: 50px;">
                        <div style="float: left;margin-left:;">
                            <a href="#" id="check-all" class="act" data-url="http://www.opplestore.com/public/app/b2c/statics/kum-img/">
                                <div style="float: left;line-height: 60px;">
                                    <img src="__PUBLIC__/img/xuanzhong.png" style="max-height: 50px;width: 20px;">
                                </div>
                                <div style="float: left;">全选</div>
                            </a>
                        </div>
                        <div style="float: left;margin-left: 10px;">
                            <div style="line-height: 25px;">共<span class="qty" style="color: red;padding-top: 5px;">3</span>件商品</div>
                            <div style="line-height: 25px;">合计:<span class="kprice" style="color: red;">￥52.00</span></div>
                        </div>
                    </div>
                </div>
                <if condition="$cart_num eq 0">
                    <a href="javascript:;" >
                        <div style="color: white;float: left;width: 35%;background: #666;text-align: center;line-height: 50px;font-weight: normal;">
                            结算
                        </div>
                    </a>
                    <else/>
                    <a href="javascript:;" id="jiesuan" >
                        <div style="color: white;float: left;width: 35%;background: #00a1f2;text-align: center;line-height: 50px;font-weight: normal;">
                            结算
                        </div>
                    </a>
                </if>

            </div>
        </div>
    </div>
    <div class="full-padding" style="margin-bottom:50px;">
        <div class="cart-pt">
            <!-- 购物车主体 -->
            <td colspan="4">
                <!-- 订单获得的优惠促销 -->
                <div class="order-promotion" id="order_promotion">
                    <h3><a href="javascript:void(0);" class="btn-collapse">-</a>订单优惠</h3>
                    <ul class="content">
                    </ul>
                </div>
            </td>

            <!-- 购物车条目 -->
            <ul class="pt-list">
                <volist name="list" id="li">
                    <li class="pt-h-item c-fix">
                        <div class="kform" id="good_goods_139_682">
                            <input type="hidden" name="obj_type" value="goods" />
                            <input type="hidden" name="goods_ident" value="goods_139_682" />
                            <input type="hidden" name="goods_id" value="139" />
                            <input type="hidden" name="min" value="1" class="min-num" />
                            <input type="hidden" name="max" value="4434" class="max-num" />
                            <input type="hidden" name="stock" value="4434" />

                            <div style="float: left;height: 79px;" >
                                <img src="__PUBLIC__/img/xuanzhong.png"
                                     <if condition="session('vip') eq 1">
                                         one-price="{$li.vip_price}"
                                         <else/>
                                         one-price="{$li.price}"
                                     </if>
                                     the-qty="{$li.goods_num}"
                                     attr="{$li.cart_id}"
                                     class="k-check act"
                                     style="max-height: 40px;margin-top: 26px;width: 20px;margin-right: 20px">
                            </div>
                            <div class="pt-h-img">
                                <a href="{:U('goods_details')}?goods_id={$li.goods_id}">
                                    <img src="__ROOT__{$li.picture}">
                                </a>
                            </div>
                            <div class="pt-h-info" style="margin-left: 125px;height: auto;">
                                <div class="pt-h-name" style="max-height: 20px;">{$li.good_name}</div>

                                <div class="pt-h-price">
                                    <div class="col2" style="width: auto;">
                                        <if condition="session('vip') eq 1">
                                            <div class="col price">￥{$li.vip_price}</div>
                                        <else/>
                                            <div class="col price">￥{$li.price}</div>
                                        </if>
                                    </div>
                                </div>
                            </div>
                            <div class="pt-h-bar c-fix" style="margin-left: 40px;margin-top: 46px;">
                                <div class="pt-num J-pt-num" style="height: 20px;line-height: 20px;">
                                    <span class="minus btn gray" style="line-height: 20px;height: 20px;width: 20px">-</span>
                                    <div class="num" style="line-height: 20px;height: 20px;">
                                        <input type="number" name="modify_quantity[goods_139_682][quantity]"
                                               style="height: 20px;line-height: 20px;position: relative;bottom: 1px;"
                                               value="{$li.goods_num}" class="num-ipt" min="1" max="200" readonly>
                                    </div>
                                    <span class="plus btn gray" style="line-height: 20px;height: 20px;width: 20px">+</span>
                                </div>
                                <div class="pt-h-del">
                                    <a data-url="javascript:;" class="del" attr="{$li.cart_id}">
                                        <img src="__PUBLIC__/img/shanchu.png" style="max-height: 20px;">
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>
                    <div style="width: 100%;background: #999;height: 1px"></div>
                </volist>


            </ul>

            <!--手动输入时修改购物车商品数量-->
            <script>
                $('.num-ipt').blur(function () {
                    var cartId = $(this).parents('.kform').find('.k-check').attr('attr');
                    var num= $(this).val();
                    $.ajax({
                        url:"{:U('cart_save')}",
                        data:{'cart_id':cartId,'num':num},
                        type:'post',
                        success:function(e){

                        }
                    })
                })
            </script>
            <script>
                //修改购物车商品数量
                $('.plus').click(function () {
                    var cartId = $(this).parents('.kform').find('.k-check').attr('attr');
                    $.ajax({
                        url:"{:U('cart_save')}",
                        data:{'cart_id':cartId,'type':'jia'},
                        type:'post',
                        success:function(e){

                        }
                    })
                })

                $('.minus').click(function () {
                    var cartId = $(this).parents('.kform').find('.k-check').attr('attr');
                    $.ajax({
                        url:"{:U('cart_save')}",
                        data:{'cart_id':cartId,'type':'jian'},
                        type:'post',
                        success:function(e){

                        }
                    })
                })
            </script>
            <script type="text/javascript">
                var o = $('#order_promotion,#unused_promotion');
                o.find('.btn-collapse').on('click',function(){
                    if( $(this).html()=='-' ){
                        $(this).html('+').parent().next().toggleClass('hide');
                        return;
                    }
                    $(this).html('-');
                    $(this).parent().next().removeClass('hide');
                    handle.eq(n).html('+');
                    list.eq(n).addClass('hide');
                });
            </script>        </div>
    </div>
</div>

<!--删除购物车商品-->
<script>
    $('.del').click(function () {
        var msg = "您真的确认要删除吗？";
        if(confirm(msg)){
            //购物车删除商品
            var cart_id = $(this).attr('attr');
            var $aaa = $(this);
            $.ajax({
                url:"{:U('cart_del')}",
                data:{'cart_id':cart_id},
                type:'post',
                success:function(e){
                    if(e == 1){
                        $aaa.parent().parent().parent().parent().remove();
                    }else{
                        alert('数据异常');
                    }
                }
            })
        }else {
            return false;
        }

    })
</script>

<!--购物车结算：获取所有选中商品-->
<script>
    $('#jiesuan').click(function () {
        var cid = "";
        if ($('.qty').html()==0){
            alert('您还没有选择商品，请选择购买的商品！');
            return false;
        }
        $('.k-check').each(function () {
            if( $(this).is('.act')){
                cid += $(this).attr('attr')+',';
            }
        })
        $('#jiesuan').attr('href',"{:U('payment')}?cid="+cid);
    })

</script>

<script type="text/javascript">
    $('.k-check').on('click',function() {
        var url  = $(this).attr('data-url');
        if ($(this).hasClass('act')){
            $(this).removeClass('act');
            $(this).attr('src','__PUBLIC__/img/weixuanzhong.png');
//            $(this).parent().siblings().find('.num').find('input').attr("disabled",true);
        }else {
            $(this).addClass('act');
            $(this).attr('src','__PUBLIC__/img/xuanzhong.png');
//            $(this).parent().siblings().find('.num').find('input').attr("disabled",false);
        }
        chenk_kum(url);
        get_jiage();
    });
    $('#check-all').on('click',function() {
        var url  = $(this).attr('data-url');
        if ($(this).hasClass('act')){
            $(this).removeClass('act');
            $(this).find('img').attr('src','__PUBLIC__/img/weixuanzhong.png');
            $('.k-check').attr('src','__PUBLIC__/img/weixuanzhong.png');
            $('.k-check').removeClass('act');
//            $('.k-check').parent().siblings().find('.num').find('input').attr("disabled",true);
        }else {
            $(this).addClass('act');
            $(this).find('img').attr('src','__PUBLIC__/img/xuanzhong.png');
            $('.k-check').attr('src','__PUBLIC__/img/xuanzhong.png');
            $('.k-check').addClass('act');
//            $('.k-check').parent().siblings().find('.num').find('input').attr("disabled",false);
        }
        get_jiage();
    });
    function chenk_kum(url) {
        var f = true;
        $('.k-check').each(function() {
            if($(this).hasClass('act')){
            }else {
                f = false;
            }
        });
        if (f){
            $('#check-all').find('img').attr('src','__PUBLIC__/img/xuanzhong.png');
            $('#check-all').addClass('act');
        }else {
            $('#check-all').find('img').attr('src','__PUBLIC__/img/weixuanzhong.png');
            $('#check-all').removeClass('act');
        }
    }

    function get_jiage() {
        var ex = /^\d+$/;
        var f = 0;
        var price = 0;
        var qty = 0;
        $('.k-check').each(function() {
            if($(this).hasClass('act')){
                var one_price = $(this).attr('one-price');
                var the_qty = $(this).attr('the-qty');
                price = one_price*the_qty+price*1;
                qty = qty*1+the_qty*1;
            }
        });
        price = price.toFixed(2);
        if (ex.test(price)){
            $('.kprice').html('￥'+price+'.00');
        }else {
            $('.kprice').html('￥'+price);
        }
        $('.qty').html(qty);
//        var params = $('<form action=""></form>');
//        $('.kform').each(function() {
//            if($(this).find('.k-check').hasClass('act')){
////                params.push($('<form action=""></form>').append($(this).clone()).serialize());
//                params.append($(this).clone());
//            }
//        });
//
//        $.ajax({
//            url:'/index.php/wap/cart-checkout.html',
//            type:'post',
//            dataType:'json',
//            data:params.serialize(),
//            success:function() {
//
//            }
//        });

    }
    get_jiage();
</script>
<script>
    (function(){
        $(window).scroll(function(e){
//        if($(this).scrollTop() > 95){
//            $('#J_total').addClass('fixed');
//        }else{
//            $('#J_total').removeClass('fixed');
//        }
        });
        $('.J-pre').bind('click',function(e){
            $(this).toggleClass('act');
            $(this).parents('.pt-h-item').find('.pre-info').toggleClass('hide');
        });

        $('#order_promotion .d-line').bind('click',function(){
            $('#J_pre_info').toggleClass('hide');
            $(this).find('.pre-list').toggleClass('hide');
        });

        // 设置商品数量
        function setQuantity(el,flag){
            var ipt = el.parent().find('.num-ipt'),
                    max = parseInt(el.parents('.pt-h-item').find('.max-num').val()),
                    min = parseInt(el.parents('.pt-h-item').find('.min-num').val()),
                    val = ipt.val(),
                    v_qty = val;

            switch(flag){
                case 1:
                    if(!/^\d+$/.test(val))
                        ipt.val(min);
                    else if(val > min){
                        ipt.val( val-1 );
                        --v_qty;
                    }
                    else if(val == min)
                        popup('此商品最少购买' + min + '件');
                    break;
                case 2:
                    if(val < max){
                        ipt.val( +val+1 );
                        ++v_qty;
                    }
                    else if(val == max)
                        popup('此商品最多只能购买' + max + '件');
                    break;
                case 3:
                    if(!/^\d+$/.test(val)) {
                        ipt.val(min);
                    } else if(val > max){
                        popup('此商品最多只能购买' + max + '件');
                        ipt.val(max);
                    } else if(val < min){
                        popup('此商品最少购买' + min + '件');
                        ipt.val(min);
                    }
                    break;
            }
            el.parent().parent().parent().find('img').attr('the-qty',v_qty);
            function popup(msg) {
                var tpl = $('<div class="popup">' + msg + '</div>').appendTo(document.body);
                var timer = setTimeout(function(){
                    tpl.remove();
                }, 3000);
            }

            var data = $('<form action=""></form>').append(el.parents('.pt-h-item').clone()).serialize();
            $.post('/index.php/wap/cart-update.html',data+"&response_type=true&k_type=cart",function(re){
                var o = JSON.parse(re),
                        promotion = $('#order_promotion .content'),
                        unuse_rule = $('#unused_promotion .content'),
                        ul = '';
                if(o.promotion){
                    if(o.promotion.order){
                        $.each(o.promotion.order,function(){
                            ul += '<li><b class="f-red">['+this.desc_tag+']</b>'+this.name+'</li>';
                        });
                        promotion.html(ul);
                        ul = '';
                    }else{
                        promotion.html('');
                    }
                }else{
                    promotion.html('');
                }
                if(o.unuse_rule){
                    $.each(o.unuse_rule,function(){
                        ul += '<li><b class="f-red">['+this.desc_tag+']</b>'+this.name+'</li>';
                        unuse_rule.html(ul);
                    });
                }else{
                    unuse_rule.html('');
                }

//            el.parents('.pt-h-item').find('.price').html(o.edit_ajax_data.buy_price);
                $('#J_total .kprice').html(o.sub_total.promotion_subtotal);
                $('#J_total .qty').html(o.number.cart_number);
            });
            get_jiage();
        }
        $('.J-pt-num').bind('click',function(e){
            var el = $(e.srcElement),
                    n = 0;
            if( !el.hasClass('btn') )return;

            if( el.hasClass('minus') )n=1;
            if( el.hasClass('plus') )n=2;

            setQuantity(el,n);

        });
        $('.num-ipt').bind('change',function(){
            setQuantity( $(this),3 );
        });

        // 移除商品
        $('.J-remove').bind('click',function(e){
//        alert($(this).attr('data-url'));return false;
            if(!confirm('确认移除商品“'+$(this).parents('li').find('.pt-h-name').html().trim()+'”？'))return false;
            var oo = $(e.target);
            var data = $('<form action=""></form>').append($(this).parents('.pt-h-item').clone()).serialize();
            $.post($(this).attr('data-url'),data+"&response_type=true",function(re){
                //remove use
//            console.log(re);
//            if(re=='ok'){
//                alert("删除成功！");
//                window.location.reload();
//            }else {
//                alert('删除失败，稍后再试！');
//            }
//            return false;
                //remove use end
                var rs = JSON.parse(re);
                if(rs.is_empty) return location.reload();
                $('#J_total .kprice').html(rs.sub_total.promotion_subtotal);
                $('#J_total .num').html(rs.number.cart_number);
                if(rs.error) return alert(rs.error);
                oo.parents('.pt-h-item').remove();
                // if(p.hasClass('item') && $('.pt-list').children().length == 2){
                //     oo.parents('.pt-h-item').remove();
                //     $('cart-pt').remove();
                // }else{
                //     p.destroy();
                // }


            });
            return false;
        });

        // 初始化购物车的收藏按钮状态
        var favmid = $.fn.cookie('S[MEMBER]');
        var gfav = $.fn.cookie("S[GFAV]["+favmid+"]");
        var gfav = decodeURIComponent(gfav);
        $('.favlist').each(function(index){
            if( gfav.split(',').indexOf( $(this).attr('data-gid') ) > -1 )
            {
                $(this).removeClass('btn-addfav').addClass('btn-faved').html('已收藏');
            }else{
                $(this).removeClass('btn-faved').addClass('btn-addfav').html('收藏');
            }
        });



        // 购物车结算
        $('.J_settlement').bind('click',function(e){
            if ($('.qty').html()==0){
                alert('您还没有选择商品，请选择购买的商品！');
                return false;
            }

            var form =$('<form class="hide"></form>').attr({
                'action':'/index.php/wap/cart-checkout.html',
                'method':'post'
            });
            var input = '';
            $('.k-check').each(function() {
                if ($(this).hasClass('act')){
                    input +=$(this).parent().parent().html();
                }
            });
            form.append(input);
//        $('.pt-list').clone()
            $(document.body).append(form);
//        console.log(form);
            form.submit();
            return false;
        });

    })();
</script>
<div class="msg" id="success">
    <table align="center">
        <tbody><tr>
            <td>
                <div class="checkout-success"></div>
            </td>
        </tr>
        </tbody></table>
</div>
<script>
    (function(){
        $('.J-tab .trigger').on('tap',function(e){
            if($(this).attr('data-url') && $(this).attr('data-url') != 'true'){
                $.get($(this).attr('data-url'),function(re){
                    $($('.J-tab .panel')[$(this).index()]).append(re);
                }.bind(this));
                $(this).attr('data-url','true');
            }
            $(this).add($('.J-tab .panel')[$(this).index()]).addClass('act').siblings('.act').removeClass('act');
        });

        function changeVerify(element, hasEvent) {
            $.each(element,function(){
                var url;
                var img;
                var el = this;
                if(el.tagName === 'IMG') {
                    img = el;
                    url = el.getAttribute('src').split('?')[0];
                }
                else if(el.tagName === 'A') {
                    img = el.previousElementSibling;
                    url = el.getAttribute('href');
                }
                if(hasEvent) $(el).on('touchend click', function(e){e.preventDefault();}).on('tap longTap', changeCode.bind(el, img, url));
                else changeCode(img, url);
            });
        }
        function changeCode(img, url){
            url = url || img.src.split('?')[0];
            var random = +new Date;
            img.src = url + '?' + random;
            return false;
        }
        changeVerify($('form .auto-change-verify-handle'), true);

        $(document).on('submit', 'form', function(){
            var sel = $('.region select'),
                    region_false = false;
            $.each(sel,function(){
                if((this.style.visibility == 'visible') && (this.selectedIndex==0))
                    region_false = true;
            });
            if(region_false){
                alert('请选择完整地区！');
                return false;
            }

            var required = $(this).find('input[required]');

            if(required.length){
                var checkEmpty = false, ipt;
                $.each(required,function(){
                    ipt = $(this);
                    if(ipt.val()=='' && ipt.offset().height){
                        checkEmpty = ipt;
                        if(ipt.attr('data-caution'))
                            alert(ipt.attr('data-caution'));
                        return false;
                    }
                });
                if( checkEmpty )return false;
            }
            if($(this).attr('data-type') == 'ajax'){
                var self = $(this);
                $(this).find('[type=submit]').prop('disabled', true);
                $[$(this).attr('method')]($(this).attr('action'),$(this).serialize(),function(re){
                    try{
                        re = JSON.parse(re);
                    }catch(e) {}
                    var update = self.attr('data-update');
                    if(re.error){
                        if($('form .auto-change-verify-handle').length > 0){
                            $('form .auto-change-verify-handle').trigger('tap');
                        }
                        self.find('[type=submit]').prop('disabled', false);
                        return alert(re.error);
                    }else{
                        if($(update).size()) {
                            $(update).html(re);
                        }
                        else {
                            $('#success .checkout-success').html(re.success);
                            new Dialog('#success',{title:'提交成功！',type:'noclose'});
                            setTimeout(function(){location.href = re.redirect},1000);
                        }
                    }
                });
                return false;
            }else{
                return true;
            }
        });


        var e = $.fn.cookie('UNAME')?$.fn.cookie('UNAME'):'',

                cartNum = $.fn.cookie('S[CART_NUMBER]')?$.fn.cookie('S[CART_NUMBER]'):'';

        e += $.fn.cookie('LV_NAME')?$.fn.cookie('LV_NAME'):'';

        if(e){
            $("#footerloginuname").text(decodeURIComponent(e));
            $("#footerlogout").show();
            if($("#footerlogin"))
                $("#footerlogin").hide();
        }else{
            $("#footerlogin").show();
            if($("#footerlogout"))
                $("#footerlogout").hide();
        }
        if(cartNum)$('.cart-num').html(cartNum).show();
        else $('.cart-num').hide();
    })();
</script>
</body>
</html>

